package com.company.jd;

import java.util.Scanner;

public class Main1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int res = 0;
        for(int i = n;i <= m;i++){
            if(isData(i)){
                res++;
            }
        }
        System.out.println(res);
    }


    private static boolean isData(int n) {
        if(n <= 1){
            return false;
        }
        if(n >= 2 && n <= 9){
            return isSuShu(n);
        }
        // 对10以上的数进行拆分

        StringBuilder str = new StringBuilder();
        while (n != 0){
            str.append(n % 10);
            n /= 10;
        }
        // 得到每一位
        char[] temp = str.reverse().toString().toCharArray();
        for(int i = 0;i < temp.length;i++){
            int res = 0;
            int weishu = temp.length - 2;
            for(int j = 0;j <temp.length;j++){
                if(i != j){
                    res += (temp[j] - '0' ) * Math.pow(10,weishu);
                    weishu--;
                }
            }
            int t = res;
            StringBuilder sb = new StringBuilder();
            while (t != 0){
                sb.append(t % 10);
                t /= 10;
            }
            char[] tm = sb.reverse().toString().toCharArray();
            if(isSuShu(res) && isPalidmote(tm,0,tm.length - 1)){
                return true;
            }
        }
        return false;

    }

    // 判断是否为回文序列
    private static boolean isPalidmote(char[] ch,int i,int j){
        while (i < j){
            if(ch[i++] != ch[j--]){
                return false;
            }
        }
        return true;
    }



    // 判断是否为素数
    private static boolean isSuShu(int m){
        if(m == 2){
            return true;
        }
        if((m & 1) == 0){
            return false;
        }
        int edge = (int)Math.sqrt(m) + 1;
        for(int i = 2;i <= edge;i++){
            if((m % i) == 0){
                return false;
            }
        }
        return true;
    }

}
